/**
 * Project:   dtu.fmes.googleloon
 * File:      SimulationStateHistorySingleton.java
 * License: 
 *            This file is licensed under GNU General Public License version 3
 *            http://www.gnu.org/licenses/gpl-3.0.txt
 *
 * Copyright:	Nicolai Sonne [ NicolaiSonne@hotmail.com.com ]
 * Date:      Dec 11, 2013
 */

package dtu.fmes.loon.singletons;

import dtu.fmes.loon.model.SimulationState;
import dtu.fmes.loon.model.SimulationStateHistory;

/**
 * Singleton used for holding history/results of simulation
 * 
 * @author Nicolai Sonne
 */
public class SimulationStateHistorySingleton {

	private static SimulationStateHistorySingleton INSTANCE = null;

	public static synchronized SimulationStateHistorySingleton instance() {
		if (INSTANCE == null) {
			INSTANCE = new SimulationStateHistorySingleton();
		}
		return INSTANCE;
	}

	private SimulationStateHistory simulationStateHistory;

	private SimulationStateHistorySingleton() {
		simulationStateHistory = new SimulationStateHistory();
	}

	public void add(SimulationState state) {
		getSimulationStateHistory().getStateHistory().add(state);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		SimulationStateHistorySingleton other = (SimulationStateHistorySingleton) obj;
		if (simulationStateHistory == null) {
			if (other.simulationStateHistory != null) {
				return false;
			}
		} else if (!simulationStateHistory.equals(other.simulationStateHistory)) {
			return false;
		}
		return true;
	}

	public SimulationStateHistory getSimulationStateHistory() {
		return simulationStateHistory;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (simulationStateHistory == null ? 0 : simulationStateHistory.hashCode());
		return result;
	}

	public void setSimulationStateHistory(SimulationStateHistory simulationStateHistory) {
		this.simulationStateHistory = simulationStateHistory;
	}

	@Override
	public String toString() {
		return "SimulationStateHistorySingleton [simulationStateHistory=" + simulationStateHistory + "]";
	}
}
